<template>
    <div class="login-container">
        <div class="login-box">
            <div class="login-header">
                <div class="logo">
                    <el-icon class="logo-icon">
                        <ShoppingCart />
                    </el-icon>
                </div>
                <h2>超市管理系统</h2>
                <p>SUPERMARKET MANAGEMENT SYSTEM</p>
            </div>

            <el-form ref="loginFormRef" :model="form" :rules="loginRules" class="login-form">
                <el-form-item prop="username">
                    <el-input v-model="form.name" placeholder="请输入用户名" :prefix-icon="User" size="large"
                        clearable />
                </el-form-item>

                <el-form-item prop="password">
                    <el-input v-model="form.password" type="password" placeholder="请输入密码" :prefix-icon="Lock"
                        size="large" show-password @keyup.enter="handleLogin" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" :loading="loading" class="login-button" size="large" @click="handleLogin">
                        登录
                    </el-button>
                </el-form-item>
            </el-form>

        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import type { FormInstance } from 'element-plus'
import { User, Lock, ShoppingCart } from '@element-plus/icons-vue'
import { AdminUtils, loginForm, loginRules } from '@/models/adminModel'

const loginFormRef = ref<FormInstance>()
const loading = ref(false)

const form = ref<loginForm>({name: '', password: ''})

const handleLogin = async () => {
  if (!loginFormRef.value) return

  await loginFormRef.value.validate((valid) => {
    if (valid) {
      // 这里应该调用登录 API
      AdminUtils.login(form.value)
    } 
  })
}
</script>

<style scoped>
.login-container {
    height: 98%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #83bff6 0%, #188df0 100%);
    position: relative;
    overflow: hidden;
}

.login-container::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
    top: -50%;
    left: -50%;
    animation: rotate 30s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.login-box {
    width: 420px;
    padding: 40px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, #409eff 0%, #2378f7 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(35, 120, 247, 0.3);
}

.logo-icon {
    font-size: 55px;
    color: #fff;
}

.login-header h2 {
    font-size: 28px;
    color: #303133;
    margin-bottom: 8px;
    font-weight: 600;
}

.login-header p {
    font-size: 14px;
    color: #909399;
    letter-spacing: 1px;
}

.login-form {
    margin-top: 40px;
}

:deep(.el-input__wrapper) {
    box-shadow: 0 0 0 1px #dcdfe6 inset;
    padding: 4px 11px;
    height: 44px;
    transition: all 0.3s ease;
}

:deep(.el-input__wrapper.is-focus) {
    box-shadow: 0 0 0 1px var(--el-color-primary) inset;
}

:deep(.el-input__inner) {
    font-size: 15px;
}

:deep(.el-input__prefix-inner) {
    font-size: 18px;
    margin-right: 8px;
}

.form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 0 2px;
}

.login-button {
    width: 100%;
    height: 44px;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #409eff 0%, #2378f7 100%);
    border: none;
    transition: all 0.3s ease;
}

.login-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(35, 120, 247, 0.3);
}

.login-footer {
    margin-top: 30px;
    text-align: center;
    color: #909399;
    font-size: 13px;
    line-height: 1.6;
}

/* 添加响应式设计 */
@media screen and (max-width: 576px) {
    .login-box {
        width: 90%;
        padding: 30px 20px;
    }

    .logo {
        width: 60px;
        height: 60px;
    }

    .logo-icon {
        font-size: 30px;
    }

    .login-header h2 {
        font-size: 24px;
    }
}
</style>